package top.xchch.creational.prototype.version02;

public class Main {
    public static void main(String[] args) throws CloneNotSupportedException {
        Sheep friend = new Sheep("jack", 2, "black", null);
        Sheep sheep = new Sheep("tom", 1, "white", friend);

        Sheep clone01 = sheep.clone();
        clone01.setAge(3);
        Sheep clone02 = sheep.clone();

        System.out.println(sheep == clone01); // false 实现了克隆
        System.out.println(sheep == clone02); // false

        clone01.getFriend().setAge(5);
        System.out.println(sheep.getFriend()); // Sheep{name='jack', age=5, color='black', friend=null}
        System.out.println(clone01.getFriend()); // Sheep{name='jack', age=5, color='black', friend=null}
        System.out.println(sheep.getFriend() == clone01.getFriend()); // true 没有实现深克隆
        System.out.println(sheep.getFriend() == clone02.getFriend()); // true
    }
}
